<template>
  <div class="app-container">
    <el-form class="base-search-form" :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
      <el-form-item label="运营渠道" prop="businessChannel">
        <el-select v-model="queryParams.businessChannel" placeholder="请选择运营渠道" clearable>
          <el-option
            v-for="dict in business_channel"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="渠道号" prop="channelCode">
        <el-input
          v-model="queryParams.channelCode"
          placeholder="请输入渠道号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="推送时间" prop="pushTime">
        <el-date-picker clearable
          v-model="queryParams.pushTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择推送时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="推送状态" prop="pushStatus">
        <el-select v-model="queryParams.pushStatus" placeholder="请选择推送状态" clearable>
          <el-option
            v-for="dict in plat_order_push_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="订单状态" prop="orderStatus">
        <el-select v-model="queryParams.orderStatus" placeholder="请选择订单状态" clearable>
          <el-option
            v-for="dict in plat_push_order_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="支付回调时间" prop="notifyTime">
        <el-date-picker clearable
          v-model="queryParams.notifyTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择支付回调时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="用户编号" prop="platformUserId">
        <el-input
          v-model="queryParams.platformUserId"
          placeholder="请输入用户编号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="渠道用户id" prop="partnerId">
        <el-input
          v-model="queryParams.partnerId"
          placeholder="请输入渠道用户id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户手机号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入用户手机号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司id" prop="companyId">
        <el-input
          v-model="queryParams.companyId"
          placeholder="请输入公司id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分公司id" prop="subCompanyId">
        <el-input
          v-model="queryParams.subCompanyId"
          placeholder="请输入分公司id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易时间" prop="payTime">
        <el-date-picker clearable
          v-model="queryParams.payTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择交易时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="商户订单号" prop="outTradeNo">
        <el-input
          v-model="queryParams.outTradeNo"
          placeholder="请输入商户订单号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易流水号" prop="transactionId">
        <el-input
          v-model="queryParams.transactionId"
          placeholder="请输入交易流水号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机具订单号" prop="machineOutTradeNo">
        <el-input
          v-model="queryParams.machineOutTradeNo"
          placeholder="请输入机具订单号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付模式" prop="payMode">
        <el-select v-model="queryParams.payMode" placeholder="请选择支付模式" clearable>
          <el-option
            v-for="dict in plat_order_pay_mode"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="支付渠道" prop="payChannel">
        <el-select v-model="queryParams.payChannel" placeholder="请选择支付渠道" clearable>
          <el-option
            v-for="dict in plat_order_pay_channel"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <div class="base-container mb-50px">
      <el-row :gutter="10" class="mb-10px">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['bus:platOrderPushRecord:export']"
          >导出</el-button>
        </el-col>
        <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table border v-loading="loading" :data="platOrderPushRecordList" @selection-change="handleSelectionChange">
        <!-- <el-table-column label="订单推送唯一标识id" align="center" prop="pushId" /> -->
        <!-- <el-table-column label="分发流水号，由码平台生成" align="center" prop="refNo" /> -->
        <!-- <el-table-column label="当前第几次重试,从0开始，0-代表第一次分发没有重试" align="center" prop="retryCount" /> -->
        <el-table-column label="运营渠道" align="center" prop="businessChannel">
          <template #default="scope">
            <dict-tag :options="business_channel" :value="scope.row.businessChannel"/>
          </template>
        </el-table-column>
        <el-table-column label="渠道号" align="center" prop="channelCode" />
        <el-table-column label="推送的地址" align="center" prop="pushUrl" width="150" show-overflow-tooltip />
        <el-table-column label="推送内容" align="center" prop="pushContent" width="150" show-overflow-tooltip />
        <el-table-column label="推送返回" align="center" prop="pushResp" width="150" show-overflow-tooltip />
        <el-table-column label="推送时间" align="center" prop="pushTime" width="150">
          <template #default="scope">
            <span>{{ parseTime(scope.row.pushTime, '{y}-{m}-{d} {h}:{i}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="推送状态" align="center" prop="pushStatus" width="100">
          <template #default="scope">
            <dict-tag :options="plat_order_push_status" :value="scope.row.pushStatus"/>
          </template>
        </el-table-column>
        <el-table-column label="订单状态" align="center" prop="orderStatus" width="100">
          <template #default="scope">
            <dict-tag :options="plat_push_order_status" :value="scope.row.orderStatus"/>
          </template>
        </el-table-column>
        <el-table-column label="支付回调时间" align="center" prop="notifyTime" width="150">
          <template #default="scope">
            <span>{{ parseTime(scope.row.notifyTime, '{y}-{m}-{d} {h}:{i}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="用户编号" align="center" prop="platformUserId" width="120" show-overflow-tooltip />
        <el-table-column label="渠道用户id" align="center" prop="partnerId" width="120" show-overflow-tooltip />
        <el-table-column label="用户手机号" align="center" prop="mobile" width="120" />
        <el-table-column label="公司名称" align="center" prop="companyName" width="120" show-overflow-tooltip />
        <el-table-column label="分公司名称" align="center" prop="subCompanyName" width="120" show-overflow-tooltip />
        <el-table-column label="交易时间" align="center" prop="payTime" width="150">
          <template #default="scope">
            <span>{{ parseTime(scope.row.payTime, '{y}-{m}-{d} {h}:{i}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="实际扣款金额" align="center" prop="actualFee" width="110">
          <template #default="scope">
            <span>{{ formatAmount(scope.row.actualFee) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="商户订单号" align="center" prop="outTradeNo" width="150" show-overflow-tooltip />
        <el-table-column label="交易流水号" align="center" prop="transactionId" width="150" show-overflow-tooltip />
        <el-table-column label="机具订单号" align="center" prop="machineOutTradeNo" width="150" show-overflow-tooltip />
        <el-table-column label="支付模式" align="center" prop="payMode" width="80">
          <template #default="scope">
            <dict-tag :options="plat_order_pay_mode" :value="scope.row.payMode"/>
          </template>
        </el-table-column>
        <el-table-column label="支付渠道" align="center" prop="payChannel" width="80">
          <template #default="scope">
            <dict-tag :options="plat_order_pay_channel" :value="scope.row.payChannel"/>
          </template>
        </el-table-column>
        <el-table-column label="支付异常说明" align="center" prop="exDetail" width="150" show-overflow-tooltip />
      </el-table>
    </div>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup name="PlatOrderPushRecord">
import { listPlatOrderPushRecord } from "@/api/bus/platOrderPushRecord"

const { proxy } = getCurrentInstance()
const { plat_order_push_status, business_channel, plat_order_pay_mode, plat_order_pay_channel, plat_push_order_status } = proxy.useDict('plat_order_push_status', 'business_channel', 'plat_order_pay_mode', 'plat_order_pay_channel', 'plat_push_order_status')

const platOrderPushRecordList = ref([])
const loading = ref(true)
const showSearch = ref(true)
const total = ref(0)

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    businessChannel: null,
    channelCode: null,
    pushTime: null,
    pushStatus: null,
    orderStatus: null,
    notifyTime: null,
    platformUserId: null,
    partnerId: null,
    mobile: null,
    companyId: null,
    subCompanyId: null,
    payTime: null,
    outTradeNo: null,
    transactionId: null,
    machineOutTradeNo: null,
    payMode: null,
    payChannel: null,
  }
})

const { queryParams } = toRefs(data)

/** 查询交易分发记录列表 */
function getList() {
  loading.value = true
  listPlatOrderPushRecord(queryParams.value).then(response => {
    platOrderPushRecordList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('bus/platOrderPushRecord/export', {
    ...queryParams.value
  }, `交易分发记录_${proxy.getFileImportName()}.xlsx`)
}

getList()
</script>
